package svc

import (
	"github.com/zeromicro/go-zero/core/stores/cache"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"my-zero-tiktok/apps/message/models"
	"my-zero-tiktok/apps/message/rpc/internal/config"
)

type ServiceContext struct {
	Config       config.Config
	Cache        cache.Cache
	Conn         sqlx.SqlConn
	Redis        *redis.Redis
	MessageModel models.MessageModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewMysql(c.DataBase.MySQL)
	return &ServiceContext{
		Config:       c,
		Conn:         conn,
		Redis:        redis.MustNewRedis(c.GeneralRedis),
		MessageModel: models.NewMessageModel(conn, c.CacheRedis),
	}
}
